/** \file ProcessManager.h
 * \author Robotnik Automation S.L.L.
 * \version 1.2
 * \date    2012
 *
 * \brief ProcessManager Class
 * 	Clase desarrollada para la gestión de procesos. Permite lanzar, parar, reiniciar los procesos de
 *  forma sencilla.
 * (C) 2012 Robotnik Automation, SLL
*/


#ifndef _PROCESSMANAGER_H
#define _PROCESSMANAGER_H

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

#define PROCESS_OK				0
#define PROCESS_ERROR_FORK		-1
#define PROCESS_ERROR_EXEC		-2
#define PROCESS_ERROR_WAITING	-3
#define PROCESS_RUNNING			-4
#define PROCESS_ERRROR_KILL		-5


//! Class for create and manage processes
class ProcessManager{

private:
	//! PID of all the processes
	//vector<pid_t> vProcessPID;
	pid_t pid_skype;
	pid_t pid_image_view;
	pid_t pid_rviz;
	pid_t pid_OpenRAVE;

public:
	//! Constructor
	ProcessManager(){
        pid_t pid_skype = -1;
        pid_t pid_image_view = -1;
        pid_t pid_rviz = -1;
        pid_t pid_OpenRAVE = -1;
	};
	//! Destructor
	~ProcessManager(){};
    //! Exec another program
	int ExecProcess(char *program_path, char **args);

	//! Creates a new process and exec player server with kanban driver
	int ExecSkype();
    int ExecImageView(char *topic);
	int ExecRviz();
	int ExecOpenRAVE(int object_id);

	//! Waits for the termination of Kanban
	int WaitSkype();
    int WaitImageView();
	int WaitRviz();
	int WaitOpenRAVE();

	//! Sends a signal to the process Kanban to finish the execution
	int ExitSkype();
    int ExitImageView();
	int ExitRviz();
	int ExitOpenRAVE();

	//! Kills the process Kanban
	int KillSkype();
    int KillImageView();
	int KillRviz();
	int KillOpenRAVE();

};

#endif
